﻿namespace GreenIsomer.Data.Entities.Ddl {
	using System;
	using System.Xml.Serialization;
	using System.Globalization;
	using System.ComponentModel;

	[Serializable]
	public class TypeConversion {

		public TypeConversion() { }

		[XmlAttribute("SsdlType")]
		public string SsdlType { get; set; }

		[XmlAttribute("OriginalSsdlType")]
		public string OriginalSsdlType { get; set; }

		[XmlAttribute("DatabaseType")]
		public string DatabaseType { get; set; }

		[XmlIgnore]
		public short? DatabaseSize { get; set; }

		[XmlIgnore]
		public byte? DatabaseScale { get; set; }

		[XmlIgnore]
		public byte? DatabasePrecision { get; set; }

		[XmlAttribute("DatabaseSize"), EditorBrowsable(EditorBrowsableState.Never)]
		public string SerializerDatabaseSize {
			get { return DatabaseSize.HasValue ? DatabaseSize.Value.ToString(CultureInfo.InvariantCulture) : null; }
			set { DatabaseSize = string.IsNullOrEmpty(value) ? (short?)null : Convert.ToInt16(value, CultureInfo.InvariantCulture); }
		}

		[XmlAttribute("DatabaseScale"), EditorBrowsable(EditorBrowsableState.Never)]
		public string SerializerDatabaseScale {
			get { return DatabaseScale.HasValue ? DatabaseScale.Value.ToString(CultureInfo.InvariantCulture) : null; }
			set { DatabaseScale = string.IsNullOrEmpty(value) ? (byte?)null : Convert.ToByte(value, CultureInfo.InvariantCulture); }
		}

		[XmlAttribute("DatabasePrecision"), EditorBrowsable(EditorBrowsableState.Never)]
		public string SerializerDatabasePrecision {
			get { return DatabasePrecision.HasValue ? DatabasePrecision.Value.ToString(CultureInfo.InvariantCulture) : null; }
			set { DatabasePrecision = string.IsNullOrEmpty(value) ? (byte?)null : Convert.ToByte(value, CultureInfo.InvariantCulture); }
		}

	}

}